/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package gourmetgrossisten;

import interfaces.ObserverListenerInterface;
import interfaces.RemoteActionInterface;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;

/**
 *
 * @author Jeppe
 */
public class ObserverListener extends UnicastRemoteObject implements ObserverListenerInterface{
    
    private ArrayList<ActionListener> actionListeners;
    
    public ObserverListener (ActionListener listener) throws RemoteException{
        actionListeners = new ArrayList<>();
        actionListeners.add(listener);
    }
    
    @Override
    public void notifyClient(RemoteActionInterface rai) throws RemoteException{
        for (ActionListener actionListener : actionListeners) {
            actionListener.actionPerformed(new ActionEvent(rai.getSource(), rai.getCode(), rai.getCommand()));
        }
    }
    
}
